<div class="boxer">
<div class="box">
		<div class="catname">
			<h2 class="jiaose-list-ico">角色列表</h2>
			{{if haspermission $.userId "role:add"}}
				<a href="/role/add/">新增角色</a>
			{{end}}
		</div>

		<div class="default-table-box">
			<div class="default-table">
				<table border="0" cellspacing="0" cellpadding="0" width="100%">
					<tr>
						<th width="75">序号</th>
						<th>角色名称</th>
						<th width="20%">状态</th>
						<th width="15%">人员数量</th>
						<th width="15%">操作</th>
					</tr>
					 {{range $ind,$elem := .Page.List}}
			          <tr style="text-align:center;">
			            <td>{{serialNumber $ind 1 $.Page.PageNo $.SizePage}}</td>
			            <td>{{$elem.Name}}</td>
						<td>
						{{if eq $elem.Status 1}}
						启用
						{{else}}
						停用
						{{end}}
						</td>
						<td>{{$elem.Description}}</td>
			            <td>	
						{{if haspermission $.userId "role:perm"}}
							{{if and (ne $elem.Name "超级管理员")  (ne $elem.Id 1)}}
								<a href="/role/perm/{{.Id}}" class="operation qxfp" title="权限分配"></a>
							{{end}}
						{{end}}
						{{if haspermission $.userId "role:edit"}}
						<a href="/role/edit/{{.Id}}" class="operation jsxg" title="修改"></a>
						{{end}}
						{{if haspermission $.userId "role:delete"}}
							{{if and (ne $elem.Name "超级管理员")  (ne $elem.Id 1)}}
								<a href="javascript:;" class="operation del" title="删除" roleid="{{.Id}}" count="{{$elem.Description}}"></a>
			           		{{end}}
							{{end}}
						 </td>
			          </tr>
       			   {{end}}
				</table>
			</div>
			<div class="default-pages margin_ten">
				<form method="post" class="pageForm">
					<input type="hidden" name="PageNo" value="{{.Page.PageNo}}"/>
					<input type="hidden" name="SizePage" value="{{.SizePage}}"/>
				</form>
				<div>共{{.Page.TotalCount}}条记录，每页&nbsp;<em><b>{{.SizePage}}</b><i>^</i><ul><li data-num="10">10</li><li data-num="20">20</li><li data-num="40">40</li></ul></em>条</div>
				<ul>
					<li><span>{{.Page.PageNo}}/{{.Page.TotalPage}}页</span></li>
					<li><a href="javascript:void(0)" id="first">首页</a></li>
					<li><a href="javascript:void(0)" id="pre">上一页</a></li>
					<li><a href="javascript:void(0)" id="next" total="{{.Page.TotalPage}}">下一页</a></li>
					<li><a href="javascript:void(0)" id="last" pageNo="{{.Page.TotalPage}}">尾页</a></li>
					<li><span>跳转至第</span></li>
					<li><input type="text" id="jump"/></li>
					<li><span>页</span></li>
				</ul>

			</div>
		</div>
	</div>
	</div>
	<script type="text/javascript">
jQuery(function($){
	$("#jump").on("blur",function(){
		var jump=$(this).val()
		if(jump<=parseInt($("#next").attr("total"))&&jump>=1){
			$("[name=PageNo]").val(jump);
			$(".pageForm").attr("action",window.location).submit()
		}else{
			$(this).val("")
		}
	});
	//首页
	$("#first").on("click",function(){
		$("[name=PageNo]").val(1);
		$(".pageForm").attr("action",window.location).submit()
	});
	//尾页
	$("#last").on("click",function(){
		$("[name=PageNo]").val($(this).attr("PageNo"));
		$(".pageForm").attr("action",window.location).submit()
	});
	//上一页
	$("#pre").on("click",function(){
		if(parseInt($("[name=PageNo]").val())-1>=1){
			$("[name=PageNo]").val(parseInt($("[name=PageNo]").val())-1);
			$(".pageForm").attr("action",window.location).submit()
		}
	});
	//下一页
	$("#next").on("click",function(){
		if(parseInt($("[name=PageNo]").val())+1<=parseInt($(this).attr("total"))){
			$("[name=PageNo]").val(parseInt($("[name=PageNo]").val())+1);
			$(".pageForm").attr("action",window.location).submit()
		}
	});
	$(".default-pages div em").toggle(function(){
		$(this).find("ul").show();
	},function(){
		$(this).find("ul").hide();
	});

	$(".default-pages div ul li").on("click",function(){
		$(".default-pages div em b").text($(this).data("num"));
		$("[name=PageNo]").val(1);
		$("[name=SizePage]").val($(this).data("num"));
		$(".pageForm").attr("action",window.location).submit();
	});

	$(".default-table").find(".del").on("click",function(){
		var id=$(this).attr("roleid")
		var count=$(this).attr("count")
		if(count==0){
	    	layer.confirm('确认删除当前这个角色吗？删除后无法恢复！', {
	    	  title: '删除',
			  btn: ['是的','取消'], //按钮
			  yes: function(index){
			  	var this_id = $(this).data("id");
				window.location.href="/role/delete/"+id
			  	layer.close(index);
			  }
			});
		}else{
			layer.open({
			  type: 1
			  ,offset: 't' //具体配置参考：offset参数项
			  ,content: '<div style="font-size:15px;padding:25px;">当前角色下存在用户,不能删除</div>'
			  ,btn: '确认'
			  ,btnAlign: 'c' //按钮居中
			  ,shade: 0 //不显示遮罩
			  ,yes: function(){
			    layer.closeAll();
			  }
			})
		}
    });
});
</script>